<?php
namespace common\records;
use Yii;
use yii\db\ActiveRecord;

class ToyMachine extends ActiveRecord
{
    /**
    ** @return string 返回该AR类关联的数据表名
    **/
    public static function tableName()
    {
        return 'toy_machine';
    }

    public function rules()
    {
        return [
            [['mid','address','coin','toy_id'],'required'],
            [['mid','address','description'],'string'],
            [['coin','toy_id'],'integer'],
            ];
    }
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'mid' => '机器编号',
            'toy_id' => '娃娃类型',
            'left_toy' => '剩余娃娃数',
            'coin' => '消耗娃娃币',
            'address' => '安置地址',
            'description' => '描述',
            'timestamp' => '登记时间',
            ];
    }

    public function beforeSave($insert)
    {
        if (parent::beforeSave($insert)) {
            if ($insert == true) {
                $this->timestamp = date('Y-m-d H:i:s');
            }
            return true;
        }
        return false;
    }
    
}
